function isEmpty(a){
            if (a === "") return true; //检验空字符串
            if (a === "null") return true; //检验字符串类型的null
            if (a === "undefined") return true; //检验字符串类型的 undefined
            if (!a && a !== 0 && a !=="") return true; //检验 undefined 和 null           
            if (Array.prototype.isPrototypeOf(a) && a.length === 0 ) return true; //检验空数组
            if (Object.prototype.isPrototypeOf(a) && Object.keys(a).length === 0 ) return true;  //检验空对象
            return false;
        }
function addCookie(name,value,expireHours){
             var cookieString=name+"="+escape(value);
             //判断是否设置过期时间
             if(expireHours>0){
                    var date=new Date();
                    date.setTime(date.getTime+expireHours*3600*1000);
                    cookieString=cookieString+"; expire="+date.toGMTString();
             }
             document.cookie=cookieString;
}
function getCookie(name){
             var strCookie=document.cookie;
             var arrCookie=strCookie.split("; ");
             for(var i=0;i<arrCookie.length;i++){
                   var arr=arrCookie[i].split("=");
                   if(arr[0]==name)return arr[1];
             }
             return "";
}
function deleteCookie(name){
              var date=new Date();
              date.setTime(date.getTime()-10000);
              document.cookie=name+"=v; expire="+date.toGMTString();
}
class XNumber {
		  byteorder = "B"; //默认大端
		  dataview16 ;
		  dataview32 ;
		  dataview64 ;
		  constructor () {
		  }
		  setByteOrder(s){
			this.byteorder = s;
		  }
		  convert(bytes){
			   /*
					ABCD = 0, // 大端
					BADC = 1, // 大端反转
					DCBA = 3, // 小端
					CDAB = 2, // 小端反转
				*/
				//默认大端ABCD,不处理
				var mbytes=[];
				if (bytes.length==2)
				{
					//16位不进行转换
					mbytes=bytes;
				}else{
					if (this.byteorder=="B") {
						mbytes=bytes;
					}else if(this.byteorder=="BS"){
						//大端交换
						if (bytes.length==4){
							mbytes=[bytes[1],bytes[0],bytes[3],bytes[2]];
						}else if (bytes.length==8){
							mbytes = [bytes[1],bytes[0],bytes[3],bytes[2],,bytes[5],bytes[4],bytes[7],bytes[6]];
						}
					}else if(this.byteorder=="L"){
						//小端翻转
						mbytes = bytes.reverse();
					}else if(this.byteorder=="LS"){
						//小端翻转+交换
						if (bytes.length==4){
							mbytes=[bytes[2],bytes[3],bytes[0],bytes[1]];
						}else if (bytes.length==8){
							//mbytes = [bytes[7],bytes[6],bytes[5],bytes[4],bytes[3],bytes[2],bytes[1],bytes[0]];
							mbytes = [bytes[6],bytes[7],bytes[4],bytes[5],bytes[2],bytes[3],bytes[0],bytes[1]];
						}
					}
				}
				var dataview = new DataView(new ArrayBuffer(mbytes.length));	
				for (var i = 0; i < mbytes.length; i++) {
					 dataview.setUint8(i, mbytes[i]);
				}
				return dataview
		  }
		  setBytes(bytes){
			 var alen=bytes.length;
			 if (alen==2)
			 {
				//16位
				this.dataview16 = this.convert(bytes.slice(0,2));
			 }else if(alen==4){
			 	//32位
				this.dataview32 = this.convert(bytes.slice(0,4));
			 }else if(alen==8){
				//64位
				this.dataview64 = this.convert(bytes.slice(0,8));
			 }
			
		  }/*
		  setHexString(str){
			var bytes=  hexToBytes(str);	
			if (this.byteorder=="L")
			{
				//小端翻转
				bytes = bytes.reverse();
			}
			this.dataview16 = new DataView(new ArrayBuffer(bytes.length));	
			for (var i = 0; i < bytes.length; i++) {
				this.dataview.setUint8(i, bytes[i]);
			}
		  }*/
		  //将字节数组转成有符号的8位整型，大端字节序
		  toInt8() {
			  if (this.dataview16.byteLength>=1)
			  {
				  return this.dataview16.getInt8();
			  }else{
				  return "---";
			  }				
		  }
			//将字节数组转成无符号的8位整型，大端字节序
		  toUint8() {
			  if (this.dataview16.byteLength>=1)
			  {
				  return this.dataview16.getUint8();
			  }else{
				  return "---";
			  }	
			}
			//将字节数组转成有符号的16位整型，大端字节序
		  toInt16() {
			  if (this.dataview16.byteLength>=2)
			  {
				  return this.dataview16.getInt16();
			  }else{
				  return "---";
			  }	
			}
			//将字节数组转成无符号的16位整型，大端字节序
		  toUint16() {
			  /*if (this.dataview16.byteLength>=2)
			  {
				 return this.dataview16.getUint16();
			  }else{
				  return "---";
			  }	*/
				try{
					return this.dataview16.getUint16();
				}catch(ex){
					return "---";
				}
			}
			//将字节数组转成有符号的32位整型，大端字节序
		  toInt32() {
			  /*if (this.dataview32.byteLength>=4)
			  {
				 return this.dataview32.getInt32();
			  }else{
				  return "---";
			  }	*/
			  try{
					return this.dataview32.getInt32();
				}catch(ex){
					return "---";
				}
			}
			//将字节数组转成无符号的32位整型，大端字节序
		  toUint32() {
			  /*if (this.dataview32.byteLength>=4)
			  {
				 return this.dataview32.getUint32();
			  }else{
				  return "---";
			  }	*/
			  try{
					return this.dataview32.getUint32();
				}catch(ex){
					return "---";
				}
			}
			//将字节数组转成32位浮点型，大端字节序
		  toFloat32() {
			 /* if (this.dataview32.byteLength>=4)
			  {
				 return this.dataview32.getFloat32().toFixed(4);
			  }else{
				  return "---";
			  }	*/
			   try{
					return this.dataview32.getFloat32().toFixed(4);
				}catch(ex){
					return "---";
				}
			}
			//将字节数组转成64位浮点型，大端字节序
		  toFloat64() {
			  /*if (this.dataview64.byteLength>=8)
			  {
				  return this.dataview64.getFloat64();
			  }else{
				  return "---";
			  }	*/
			   try{
					return this.dataview64.getFloat64();
				}catch(ex){
					return "---";
				}
			}
		  toUint64() {
			  /*if (this.dataview64.byteLength>=8)
			  {
				  return this.dataview64.getBigUint64();
			  }else{
				  return "---";
			  }	*/
			  try{
					return this.dataview64.getBigUint64();
				}catch(ex){
					return "---";
				}
			}
		  toInt64() {
			  /*if (this.dataview64.byteLength>=8)
			  {
				 return this.dataview64.getBigInt64();
			  }else{
				  return "---";
			  }	*/
			  try{
					return this.dataview64.getBigInt64();
				}catch(ex){
					return "---";
				}
			}
	}
	
	/*16进制字符串转uint8数组*/
	//构建一个视图，把字节数组写到缓存中，索引从0开始，大端字节序
    function getView(str) {
		var originalArray=hexToBytes(str);
		//var bytes = originalArray.reverse();
		//console.log(str);
        var view = new DataView(new ArrayBuffer(bytes.length));
        for (var i = 0; i < bytes.length; i++) {
            view.setUint8(i, bytes[i]);
        }
        return view;
    }
	//将字节数组转成有符号的8位整型，大端字节序
    function toInt8(bytes) {
        return getView(bytes).getInt8();
    }
    //将字节数组转成无符号的8位整型，大端字节序
    function toUint8(bytes) {
        return getView(bytes).getUint8();
    }
    //将字节数组转成有符号的16位整型，大端字节序
    function toInt16(bytes) {
        return getView(bytes).getInt16();
    }
    //将字节数组转成无符号的16位整型，大端字节序
    function toUint16(bytes) {
        return getView(bytes).getUint16();
    }
    //将字节数组转成有符号的32位整型，大端字节序
    function toInt32(bytes) {
        return getView(bytes).getInt32();
    }
    //将字节数组转成无符号的32位整型，大端字节序
    function toUint32(bytes) {
        return getView(bytes).getUint32();
    }
    //将字节数组转成32位浮点型，大端字节序
    function toFloat32(bytes) {
        return  getView(bytes).getFloat32().toFixed(2);
    }
    //将字节数组转成64位浮点型，大端字节序
    function toFloat64(bytes) {
        return getView(bytes).getFloat64();
    }
	function toUint64(bytes) {
        return getView(bytes).getBigUint64();
    }
	function toInt64(bytes) {
        return getView(bytes).getBigInt64();
    }


    //将数值写入到视图中，获得其字节数组，大端字节序
    function getUint8Array(len, setNum) {
        var buffer = new ArrayBuffer(len);  //指定字节长度
        setNum(new DataView(buffer));  //根据不同的类型调用不同的函数来写入数值
        return new Uint8Array(buffer); //创建一个字节数组，从缓存中拿取数据
    }
    //得到一个8位有符号整型的字节数组，大端字节序
    function getInt8Bytes(num) {
        return getUint8Array(1, function (view) { view.setInt8(0, num); })
    }
    //得到一个8位无符号整型的字节数组，大端字节序
    function getUint8Bytes(num) {
        return getUint8Array(1, function (view) { view.setUint8(0, num); })
    }
    //得到一个16位有符号整型的字节数组，大端字节序
    function getInt16Bytes(num) {
        return getUint8Array(2, function (view) { view.setInt16(0, num); })
    }
    //得到一个16位无符号整型的字节数组，大端字节序
    function getUint16Bytes(num) {
        return getUint8Array(2, function (view) { view.setUint16(0, num); })
    }
    //得到一个32位有符号整型的字节数组，大端字节序
    function getInt32Bytes(num) {
        return getUint8Array(4, function (view) { view.setInt32(0, num); })
    }
    //得到一个32位无符号整型的字节数组，大端字节序
    function getUint32Bytes(num) {
        return getUint8Array(4, function (view) { view.setUint32(0, num); })
    }
    //得到一个32位浮点型的字节数组，大端字节序
    function getFloat32Bytes(num) {
        return getUint8Array(4, function (view) { view.setFloat32(0, num); })
    }
    //得到一个64位浮点型的字节数组，大端字节序
    function getFloat64Bytes(num) {
        return getUint8Array(8, function (view) { view.setFloat64(0, num); })
    }
	
	/*在16进制每2个字符之间插入特定字符*/
	function insertstr(str,ins,c){
		var asciir="";
		for (var i = 0; i < (str.length); i = i + c) {
			asciir += str.substr(i, 2)+" ";
		}
		return asciir.toUpperCase().trim();
	}
	function reverseString(str) {
		return str.split('').reverse().join('');
	}
	//ASCII码转16进制
	function strToHexCharCode(str) {
		if (str === "") {
			return "";
		} else {
			var hexCharCode = [];
			hexCharCode.push("0x");
			for (var i = 0; i < str.length; i++) {
				hexCharCode.push((str.charCodeAt(i)).toString(16));
			}
			return hexCharCode.join("");
		}
	}
	//十六进制转ASCII字符
	function hexCharCodeToStr(hexCharCodeStr) {
		hexCharCodeStr = hexCharCodeStr.replaceAll(" ","");
		var trimedStr = hexCharCodeStr.trim();
		var rawStr = trimedStr.substr(0, 2).toLowerCase() === "0x" ? trimedStr.substr(2) : trimedStr;
		var len = rawStr.length;
		if (len % 2 !== 0) {
			alert("存在非法字符!");
			return "";
		}
		var curCharCode;
		var resultStr = [];
		for (var i = 0; i < len; i = i + 2) {
			curCharCode = parseInt(rawStr.substr(i, 2), 16);
			resultStr.push(String.fromCharCode(curCharCode));
		}
		return resultStr.join("");
	}
	/*十进制数字转二进制字符*/
	function num2binarystr(x,isreverd) {
		var b = x.toString(2)
		var l=b.length;
		for(var n = 0; n < (8-l); n++) {
			b = "0" + b;     //不够的就在前面补0
				//console.log(b.length);
		}
		if (isreverd)
		{
			b= reverseString(b);
		}
		return b;
	}
	//RTU 十六进制字符串转二进制
	function hex2binarystr(hexStr) {
		hexStr = hexStr.replaceAll(" ","");
		hexStr = hexStr.trim();
		var len = hexStr.length;
		if (len % 2 !== 0) {
			alert("存在非法字符!");
			return "";
		}
		var resultStr =  [];
		var x=0;
		for (var i = 0; i < len; i = i + 2) {
			x = hex2Number(hexStr.substr(i, 2));
			var b = x.toString(2)
			var l= b.length;
			for(var n = 0; n < (8-l); n++) {
				b = "0" + b;     //不够的就在前面补0
				//console.log(b.length);
			}
			b= reverseString(b);
			//resultStr = resultStr+b;
			resultStr.push(b);
		}
		return (resultStr.join(""));
	}
	//RTU 十六进制命令转ASCII码
	function RTUCMDToASCII(hexCharCodeStr,space) {
		hexCharCodeStr = hexCharCodeStr.replaceAll(" ","");
		hexCharCodeStr = hexCharCodeStr.replaceAll("0x","");
		var len = hexCharCodeStr.length-4;
		var curCharCode;
		var hexCode =[];
		var resultStr = [];
		for (var i = 0; i < len; i++) {
			curCharCode = hexCharCodeStr.substr(i, 1);//parseInt(rawStr.substr(i, 1), 10);
			//resultStr.push(  curCharCode.toString(16)+space );
			resultStr.push(  (curCharCode.charCodeAt()).toString(16) +space );
			hexCode.push(curCharCode +space );
		}
		var asciir = "3A "+ resultStr.join("");
		//console.log(hexCode.join(""));
		var lrchexstr = LRC(hexCode.join(""));
		//console.log(lrchexstr);
		for (var i = 0; i < (lrchexstr.length); i++) {
			asciir += ((lrchexstr.substr(i, 1)).charCodeAt()).toString(16)+" ";
		}
		asciir += "0D 0A"
		return asciir.trim();
	}
	/*LCR HEX 传入16进制字符串 ，计算LRC*/
	function LRC(hexStr,space) {
		hexStr = hexStr.replaceAll(" ","");
		hexStr = hexStr.replaceAll("0x","");
		var len = hexStr.length;
		var resultStr = [];
		var sum=0;
		for (var i = 0; i < len;  i = i + 2) {
			sum += hex2Number(hexStr.substr(i, 2));
		}
		var dec = 256 - sum % 256;
        var oct = dec.toString(8);
		var hex = dec.toString(16);
		var hexascii = "";
		return hex.toUpperCase();
	}
	function dec2hexstring(dec){
		var hex = dec.toString(16);
		return hex.toUpperCase();
	}
	/**
     * 将串口奇偶设置转为字符
     * @returns {str}
     */	
	 function parseParityMode(v){
		if (v==0)return "n";
		if (v==1)return "o";
		if (v==2)return "e";
		return "";
	 }
	 var CRC = {};
	 CRC.CRC16 = function (data) {
		var len = data.length;
		if (len > 0) {
			var crc = 0xFFFF;

			for (var i = 0; i < len; i++) {
				crc = (crc ^ (data[i]));
				for (var j = 0; j < 8; j++) {
					crc = (crc & 1) != 0 ? ((crc >> 1) ^ 0xA001) : (crc >> 1);
				}
			}
			var hi = ((crc & 0xFF00) >> 8);  //高位置
			var lo = (crc & 0x00FF);         //低位置

			return [hi, lo];
		}
		return [0, 0];
	};

	CRC.isArray = function (arr) {
		return Object.prototype.toString.call(arr) === '[object Array]';
	};

	CRC.ToCRC16 = function (str, isReverse) {
		str = str.replaceAll(" ","");
		str = str.replaceAll("0x","");
		return CRC.toString(CRC.CRC16(CRC.isArray(str) ? str : CRC.strToByte(str)), isReverse);
	};
    /**
     * 将16进制字符串计算为modbus crc 16 
     * @param data 可传入16进制的8位或16位字符串 ,space 为字节间隔符
     * @returns {number}
     */
	CRC.ToModbusCRC16 = function (str, isReverse,space) {
		var str =CRC.toString(CRC.CRC16(CRC.isArray(str) ? str : CRC.strToHex(str)), isReverse);
		if (space=="")
		{
			return str;
		}
		var rtstr="";
		for (let i = 0, len = str.length; i < len; i += 2) {
           rtstr = rtstr + str.substr(i, 2)+ space ;
        }
        return rtstr.trim();  
	};

	CRC.strToByte = function (str) {
		var tmp = str.split(''), arr = [];
		for (var i = 0, c = tmp.length; i < c; i++) {
			var j = encodeURI(tmp[i]);
			if (j.length == 1) {
				arr.push(j.charCodeAt());
			} else {
				var b = j.split('%');
				for (var m = 1; m < b.length; m++) {
					arr.push(parseInt('0x' + b[m]));
				}
			}
		}
		return arr;
	};

	CRC.convertChinese = function (str) {
		var tmp = str.split(''), arr = [];
		for (var i = 0, c = tmp.length; i < c; i++) {
			var s = tmp[i].charCodeAt();
			if (s <= 0 || s >= 127) {
				arr.push(s.toString(16));
			}
			else {
				arr.push(tmp[i]);
			}
		}
		return arr;
	};

	CRC.filterChinese = function (str) {
		var tmp = str.split(''), arr = [];
		for (var i = 0, c = tmp.length; i < c; i++) {
			var s = tmp[i].charCodeAt();
			if (s > 0 && s < 127) {
				arr.push(tmp[i]);
			}
		}
		return arr;
	};

	CRC.strToHex = function (hex, isFilterChinese) {
		hex = isFilterChinese ? CRC.filterChinese(hex).join('') : CRC.convertChinese(hex).join('');

		//清除所有空格
		hex = hex.replace(/\s/g, "");
		//若字符个数为奇数，补一个0
		hex += hex.length % 2 != 0 ? "0" : "";

		var c = hex.length / 2, arr = [];
		for (var i = 0; i < c; i++) {
			arr.push(parseInt(hex.substr(i * 2, 2), 16));
		}
		return arr;
	};

	CRC.padLeft = function (s, w, pc) {
		if (pc == undefined) {
			pc = '0';
		}
		for (var i = 0, c = w - s.length; i < c; i++) {
			s = pc + s;
		}
		return s;
	};

	CRC.toString = function (arr, isReverse) {
		if (typeof isReverse == 'undefined') {
			isReverse = true;
		}
		var hi = arr[0], lo = arr[1];
		return CRC.padLeft((isReverse ? hi + lo * 0x100 : hi * 0x100 + lo).toString(16).toUpperCase(), 4, '0');
 	};
    /**
     * 将16进制字符串转为十进制数字
     * 如  HexTools.hex2Number('0x11') //17
     *     HexTools.hex2Number('21') //33
     *     HexTools.hex2Number('0xffff') //65535
     *     HexTools.hex2Number('ffff') //65535
     * @param str 可传入16进制的8位或16位字符串
     * @returns {number}
     */
    function hex2Number(str = '') {
        if (str.indexOf('0x') === 0) {
            str = str.slice(2);
        }
        return parseInt(`0x${str}`, 16);
    }

    /**
     * 将16进制字符串转为指定字节的字符串
     * @param {string} 十六进制字符串
     * @param {byteLen} 字节大小  
     * @return {string}
     */
    function hex2ByteString(str = '', byteLen = 2,space="") {
        if (str.indexOf('0x') === 0) {
            str = str.slice(2);
        }
        let len = str.length;
        let total = byteLen * 2 - len;

        if (total > 0) {
            while (total) {
                str = '0' + str;
                total--;
            }
        }
		if (space=="")
		{
			return str;
		}
		var rtstr="";
		for (let i = 0, len = str.length; i < len; i += 2) {
           rtstr = rtstr + str.substr(i, 2)+ space
        }
        return rtstr;
    }
	/**
     * 16进制数字转为指定字节的16进制字符串
     * @param 1234567890abcdef
     */
    function hexToBytes(hex) {
            for (var bytes = [], c = 0; c < hex.length; c += 2)
                bytes.push(parseInt(hex.substr(c, 2), 16));
            return bytes;
     }
	
    /**
     * 十进制数字转为指定字节的16进制字符串
     * @param num
     * @param {byteLen} 字节大小
     * @returns {string} 得到n字节的16进制字符串
     */
    function num2HexBytes(num = 0, byteLen = 1,space="") {
        const str = parseInt(num).toString(16);
        return hex2ByteString(str, byteLen,space);
    }

    /**
     * 十进制数字(这里最大为255)转为8位16进制字符串
     * @param num
     * @returns {string} 得到8位的16进制字符串
     */
    function num2Hex(num = 0) {
            return ('00' + parseInt(num).toString(16)).slice(-2).toUpperCase();
    }
	/**
     * 十进制数字(这里最大为255)转为8位16进制字符串
     * @param num
     * @returns {string} 得到8位的16进制字符串
     */
    function num2Hexs(num = 0) {
        const str = parseInt(num).toString(16);
        return hex2ByteString(str, 2,"").toUpperCase();
    }
    /**
     * hex数组转为num
     * 数组中每一元素都代表一个8位字节，16进制的数字
     * 比如：一个精确到毫秒位的时间戳数组为[ 1, 110, 254, 149, 130, 160 ]，可以用这个函数来处理，得到十进制的时间戳1576229241504
     * 比如：一个精确到秒位的时间戳数组为[ 93, 243, 89, 121 ]，可以用这个函数来处理，得到十进制的时间戳1576229241
     * @param array 按高位在前，低位在后来排列的数组，数组中每一元素都代表一个8位字节，16进制的数字
     * @return {Number}
     */
    function hexArrayToNum(array) {
        let count = 0, divideNum = array.length - 1;
        array.forEach((item, index) => count += item << (divideNum - index) * 8);
        return count;
    }

    /**
     * num转为hex数组
     * 与{hexArrayToNum}含义相反
     * @param num
     * @returns {*} 一个字节代表8位
     */
    function num2HexArray(num) {
        if (num === void 0) {
            return [];
        }
        num = parseInt(num);
        if (num === 0) {
            return [0];
        }	
        let str = num.toString(16);
        str.length % 2 && (str = '0' + str);
        const array = [];
        for (let i = 0, len = str.length; i < len; i += 2) {
            array.push(`0x${str.substr(i, 2)}`);
        }
        return array;
    }

    /**
     * 获取数据的低八位
     * @param data
     * @returns {{lowLength: number, others: Array}}
     */
    function getDataLowLength({data}) {
        // const dataPart = [];
        // data.map(item => num2HexArray(item)).forEach(item => dataPart.push(...item));
        // const lowLength = hex2Num((dataPart.length + 1).toString(16));
        // return {lowLength, others: dataPart};
    }

    /**
     * ArrayBuffer转16进制字符串
     * @param {Object} buffer
     * @returns {string} hex
     */
    function arrayBuffer2hex(buffer) {
      const hexArr = Array.prototype.map.call(
        new Uint8Array(buffer),
        function (bit) {
          return ('00' + bit.toString(16)).slice(-2);
        }
      )
      return hexArr.join('');
    }

    /**
     * ArrayBuffer转16进制字符串数组
     * @param {Object} buffer
     * @returns {Array} hexArr
     */
    function arrayBuffer2hexArray(buffer) {
      const hexArr = Array.prototype.map.call(
        new Uint8Array(buffer),
        function (bit) {
          return ('00' + bit.toString(16)).slice(-2);
        }
      )
      return hexArr;
    }

    /**
     * 16进制字符串转ArrayBuffer(默认两个字节，小端序)
     * @param {Object} dataview
     * @param {string} hex 16进制字符串
     * @param {number} offset	偏移量
     * @param {number} bytes	几个字节
     * @returns {Object} dataview
     */	
    function hex2ArrayBuffer(dataview, hex, offset, bytes = 2) {
        var num = hex2Number(hex);
        switch(bytes) {
            case 1:
                dataview.setUint8(offset, num);
                break;
            case 2:
                dataview.setUint16(offset, num, true);
                break;
            case 4:
                dataview.setUint32(offset, num, true);
                break;
            default:
        }
        return dataview;
    }

    /**
     * number 转 小端序 ArrayBuffer (默认两个字节)
     * @param {Object} dataview 
     * @param {string} num		数字
     * @param {number} offset	偏移量
     * @param {number} bytes	几个字节
     * @returns {Object} dataview
     */	
    function num2ArrayBuffer(dataview, num, offset, bytes = 2) {
        switch(bytes) {
            case 1:
                dataview.setUint8(offset, num);
                break;
            case 2:
                dataview.setUint16(offset, num, true);
                break;
            case 4:
                dataview.setUint32(offset, num, true);
                break;
            default:
        }
        return dataview;
    }

    /**
     * 小端序 ArrayBuffer 获取number (默认两个字节)
     * @param {Object} dataview 
     * @param {number} offset	偏移量
     * @param {number} bytes	几个字节
     * @returns {number} count
     */	
    function arrayBuffer2number(dataview, offset, bytes = 2) {
        let count = 0;
        switch(bytes) {
            case 1:
                count = dataview.getUint8(offset, true);
                break;
            case 2:
                count = dataview.getUint16(offset, true);
                break;
            case 4:
                count = dataview.getUint32(offset, true);
                break;
            default:
        }
        return count;
    }

    /**
     * arraybuffer（ASCLL码） 转为字符型字符串（非16进制）
     * 1个字节一个字符 Uint8
     * @param {Object} buffer
     * @return {String} 字符串
     */
    function arraybuffer2String(buffer) {
      return String.fromCharCode.apply(null, new Uint8Array(buffer));
    }

    /**
     * string 转为 arraybuffer ASCLL码
     * @param {String} str
     * @return {Object} arraybuffer
     */
    function string2Arraybuffer(str) {
      const buf = new ArrayBuffer(str.length); // 1 bytes for each char
      const bufView = new Uint8Array(buf);
      for (let i = 0, strLen = str.length; i < strLen; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
